package com.cgbl.cg.adapter

import android.text.TextUtils
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.TimeUtils
import com.cgbl.cg.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.CommentBean
import com.robot.base.utils.pic.ImageLoaderUtils

class CourseProfileCommentReplyAdapter :
    BaseQuickAdapter<CommentBean, BaseViewHolder>(R.layout.app_item_course_comment_reply) {

    override fun convert(holder: BaseViewHolder, item: CommentBean) {
        ImageLoaderUtils.displayCircle(context, holder.getView(R.id.iv_avatar), item.fromAvatar)
        holder.setText(R.id.tv_nick_name, item.fromNickName)
        holder.setText(R.id.tv_reply_content, item.content)
            .setText(R.id.tv_nick_name_1, item.toNickName)
        holder.setText(
            R.id.item_tv_time,
            TimeUtils.millis2String(item.createTime?.toLong() ?: 0, "yyyy-MM-dd hh:mm:ss")
        )
        when (item.fromAccountType) {
            "0" -> {
                holder.setText(R.id.item_tv_tag, "官方")
                    .setBackgroundResource(R.id.item_tv_tag, R.drawable.app_radius_2fd39c_6)
                    .setGone(R.id.item_tv_tag, false)
            }
            "1" -> {
                holder.setText(R.id.item_tv_tag, "作者")
                    .setBackgroundResource(R.id.item_tv_tag, R.drawable.app_radius_cc2d2d_6)
                    .setGone(R.id.item_tv_tag, false)
            }
            "2" -> {
                holder.setText(R.id.item_tv_tag, "VIP")
                    .setBackgroundResource(R.id.item_tv_tag, R.drawable.app_radius_ffc063_6)
                    .setGone(R.id.item_tv_tag, false)
            }
            else -> {
                holder.setGone(R.id.item_tv_tag, true)
            }
        }
        when (item.toAccountType) {
            "0" -> {
                holder.setText(R.id.item_tv_tag_1, "官方")
                    .setBackgroundResource(R.id.item_tv_tag_1, R.drawable.app_radius_2fd39c_6)
                    .setGone(R.id.item_tv_tag_1, false)
            }
            "1" -> {
                holder.setText(R.id.item_tv_tag_1, "作者")
                    .setBackgroundResource(R.id.item_tv_tag_1, R.drawable.app_radius_cc2d2d_6)
                    .setGone(R.id.item_tv_tag_1, false)
            }
            "2" -> {
                holder.setText(R.id.item_tv_tag_1, "VIP")
                    .setBackgroundResource(R.id.item_tv_tag_1, R.drawable.app_radius_ffc063_6)
                    .setGone(R.id.item_tv_tag_1, false)
            }
            else -> {
                holder.setGone(R.id.item_tv_tag_1, true)
            }
        }
        holder.setText(
            R.id.tv_comment_zan_num, if (TextUtils.isEmpty(item.likeCount)) "0" else item.likeCount
        )
        holder.setImageResource(
            R.id.item_iv_like, if (item.like == "1") {
                R.mipmap.ic_course_zan_checked
            } else {
                R.mipmap.ic_course_zan_uncheck
            }
        )
        val recyclerViewImg = holder.getView<RecyclerView>(R.id.recyclerView_img)
        val commentImgAdapter = CommentImgAdapter()
        recyclerViewImg.apply {
            layoutManager = GridLayoutManager(context, 3)
            adapter = commentImgAdapter
        }
        commentImgAdapter.setNewInstance(item.imageFiles as MutableList<String>?)
    }
}